﻿namespace Ngs
{
    using System;
    using System.Collections.Generic;

    public partial class ProxyCollection<T> : ICollection<T>
    {
        protected readonly List<T> List;

        #region Constructors

        public ProxyCollection()
            : this(null)
        {
        }

        public ProxyCollection(IEnumerable<T> collection)
        {
            this.List = collection != null ? new List<T>(collection) : new List<T>();
        }
        #endregion

        #region Properties

        public T this[int index]
        {
            get { return this.List[index]; }
            set { this.List[index] = value; }
        }

        public int Count
        {
            get { return this.List.Count; }
        }

        public virtual bool IsReadOnly
        {
            get { return false; }
        }
        #endregion

        #region Methods

        public void Add(T item)
        {
            OnAdd(item);
            this.List.Add(item);
        }

        public void Clear()
        {
            OnClear();
            this.List.Clear();
        }

        public bool Contains(T item)
        {
            return this.List.Contains(item);
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            this.List.CopyTo(array, arrayIndex);
        }

        #region IEnumerable<T> Members

        public IEnumerator<T> GetEnumerator()
        {
            return this.List.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        #endregion

        //public int IndexOf(T item)
        //{
        //    OnIndexOf(item);
        //    return this.list.IndexOf(item);
        //}

        //public void Insert(int index, T item)
        //{
        //    OnInsert(index, item);
        //    this.list.Insert(index, item);
        //}

        //public void RemoveAt(int index)
        //{
        //    T item = this.list[index];
        //    OnRemove(item);
        //    this.list.RemoveAt(index);
        //}

        public bool Remove(T item)
        {
            OnRemove(item);
            return this.List.Remove(item);
        }

        #endregion

        #region Partial Methods

        protected virtual void OnAdd(T item)
        { }

        protected virtual void OnClear()
        { }

        partial void OnIndexOf(T item);

        partial void OnInsert(int index, T item);

        protected virtual void OnRemove(T item)
        { }

        #endregion
    }
}
